<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <script>
            // find 找到第一个获取到符合该条件的项
            let arr = [1, 2, 3, 4];
            let newArr = arr.find((item) => item > 3);
            console.log(newArr);

            // findIndex 找到第一个符合条件的索引
            let arr1 = [1, 2, 3, 4];
            let newArr1 = arr.findIndex((item) => item > 3);
            console.log(newArr1);

            // copyWithin() 将指定位置的成员复制到其他位置
            let arr2 = [1, 2, 3, 4, 5];
            console.log(arr2.copyWithin(1, 2, 4)); // [1,3,4,4,5]

            // includes方法，判断数组中是否有该项
            let arr3 = [1, 2, 3, 4, 5];
            console.log(arr3.includes(2)); //true

            // arr.keys arr.values arr.entries
            let arr4 = [1, 2, 3, 4, 5];
            for (let index of arr4.keys()) {
                console.log(index);
            }
            for (let item of arr4.values()) {
                console.log(item);
            }
            for (let [index, item] of arr4.entries()) {
                console.log(index, item);
            }

            // fill方法 填充数组
            console.log(new Array(4).fill(4));
            let arr5 = [1, 2, 3, 4];
            console.log(arr5.fill(7, 0, 2));

            // flat将数组扁平化，可以传入参数(Number)控制拍平几层数组
            // flatmap可以将数组扁平化并传入回调
            let arr6 = [1, 2, 3, [4, 5]];
            console.log(arr6.flat());

            let arr7 = [
                1,
                2,
                3,
                4,
                [
                    [5, 6],
                    [7, 8],
                ],
            ];
            console.log(arr7.flat());
            console.log(arr7.flat(2));

            console.log(arr7.flatMap((x) => x * 2));
        </script>
    </body>
</html>
